package com.chaoyue.media.controller;


import com.chaoyue.base.model.RestResponse;
import com.chaoyue.base.utils.StringUtil;
import com.chaoyue.media.beans.po.MediaFiles;
import com.chaoyue.media.service.MediaFileService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author whr
 * @version 1.0
 * @description: TODO
 * @date 2023/5/22 21:46
 */
@Api(value = "媒资文件管理接口", tags = "媒资文件管理接口")
@RestController
@RequestMapping("/open")
public class MediaOpenController {
    @Autowired
    private MediaFileService mediaFileService;

    @ApiOperation("预览视频文件")
    @GetMapping("/preview/{mediaId}")
    public RestResponse<String> getPlayUrlByMediaId(@PathVariable String mediaId) {
        MediaFiles mediaFiles = mediaFileService.getFileById(mediaId);
        if (mediaFiles == null) {
            return RestResponse.validfail("该视频不存在");
        }
        String url = mediaFiles.getUrl();
        if(StringUtil.isEmpty(url)){
            return RestResponse.validfail("该视频正在处理中");
        }
        return RestResponse.success(url);
    }
}
